﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Strategy.Core
{
    internal class AState 
    {
        public string StateName { get; protected set; }
        protected Dictionary<ICondition, AEvent> _TableCondition = new Dictionary<ICondition,AEvent>();
        protected Dictionary<AEvent, List<ICondition>> _TableEvent = new Dictionary<AEvent, List<ICondition>>();
        public AState(string stateName)
        {
            StateName = stateName;
        }
        public AState DoTransition()
        {
            foreach (var el in _TableCondition)
            {
                if (el.Key.isFired())
                    return el.Value.Go();
                    
            }
            return this;
        }
        public void AddEdge(ICondition condition, AEvent e)
        {
            if (_TableCondition.ContainsKey(condition))
                throw new Exception();
            _TableCondition[condition] = e;
            if (!_TableEvent.ContainsKey(e))
                _TableEvent[e] = new List<ICondition>();
            _TableEvent[e].Add(condition);
        }

        public ICollection<AEvent> GetOutEvents() { return new List<AEvent>(_TableEvent.Keys); }
    }
}
